//
//  TicketPayMentResultVC.m
//  ImGuider
//
//  Created by 王鹏宇 on 2018/1/28.
//  Copyright © 2018年 imguider. All rights reserved.
//

#import "TicketPayMentResultVC.h"
#import "CityVC.h"
#import "AccountCouponVC.h"
#import "AllOrderListVC.h"
#import "PlayerItem.h"
@interface TicketPayMentResultVC ()
@property (weak, nonatomic) IBOutlet UIImageView *paymentStateImageView;

@property (weak, nonatomic) IBOutlet UILabel *paymentStateLabel;

@property (weak, nonatomic) IBOutlet UILabel *desLabel;

@property (weak, nonatomic) IBOutlet UILabel *productNameLabel;

@property (weak, nonatomic) IBOutlet UILabel *ticketNameLabel;

@property (weak, nonatomic) IBOutlet UILabel *payNumLabel;

@property (weak, nonatomic) IBOutlet UILabel *priceLabel;

@property (weak, nonatomic) IBOutlet UIView *couponView;

@property (weak, nonatomic) IBOutlet UILabel *couponLabel;

@property (weak, nonatomic) IBOutlet UIButton *leftBtn;

@property (weak, nonatomic) IBOutlet UIButton *rightBtn;
@property (weak, nonatomic) IBOutlet UIButton *couponBtn;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *couponViewH;
@property (weak, nonatomic) IBOutlet UIView *bgView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bgViewH;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topSpace;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *labelHeight;

@end

@implementation TicketPayMentResultVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.leftBtn.layer.borderWidth = 1.0f;
    self.leftBtn.layer.borderColor = kThemeColor.CGColor;
    
    self.rightBtn.layer.borderWidth = 1.0f;
    self.rightBtn.layer.borderColor = kThemeColor.CGColor;
    
    self.bgView.backgroundColor = kBGColor;
    
    self.paymentStateLabel.textColor = kTitleColor;
    self.desLabel.textColor = kContentColor;
    self.productNameLabel.textColor = kContentColor;
    self.ticketNameLabel.textColor = kContentColor;
    self.priceLabel.textColor = kContentColor;
    self.payNumLabel.textColor = kContentColor;
    self.couponLabel.textColor = kSubitleColor;
    [self.couponBtn setTitleColor:kThemeColor forState:UIControlStateNormal];
    
    [self setup];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [[PlayerItem playItemShareManager] show];
}

- (void)setup {
    
    self.topSpace.constant = kNavigationBarHeight;
    
    if (self.payState  == 1) {
        
        self.paymentStateImageView.image = [UIImage imageNamed:@"paySuccess"];
        self.paymentStateLabel.text = MYLocalizedString(@"TICKET_PAY_SUCCESS", nil);
        self.desLabel.text = MYLocalizedString(@"TICKET_SUCCESS_TIP", nil);
        [self.leftBtn setTitle:MYLocalizedString(@"TICKET_SHOW_ORDER", nil) forState:UIControlStateNormal];
        [self.rightBtn setTitle:MYLocalizedString(@"TICKET_PAY_BACKHOME", nil) forState:UIControlStateNormal];
        self.couponLabel.text = MYLocalizedString(@"TICKET_SEND_COUPON", nil);
        self.couponView.hidden = NO;
        self.bgViewH.constant = 120;
        self.couponLabel.text =[NSString stringWithFormat:MYLocalizedString(@"TICKET_SEND_COUPON", nil),self.ticketOrderModel.PersonNum];
    }else if(self.payState == 2){
        
        self.couponViewH.constant = 0.f;
         self.paymentStateImageView.image = [UIImage imageNamed:@"payFail"];
        self.paymentStateLabel.text = MYLocalizedString(@"TICKET_PAY_FAILD", nil);
        self.desLabel.text=@"";
        self.labelHeight.constant = 60;
        [self.leftBtn setTitle:MYLocalizedString(@"TICKET_PAY_RETRY", nil) forState:UIControlStateNormal];
        [self.rightBtn setTitle:MYLocalizedString(@"TICKET_PAY_BACKHOME", nil) forState:UIControlStateNormal];
        
        self.couponView.hidden = YES;
        self.bgViewH.constant = 96;
    }
    
    [self.couponBtn setTitle:MYLocalizedString(@"PUBLIC_SHOW_DETAIL", nil) forState:UIControlStateNormal];
    
    self.productNameLabel.text = MYLocalizedString(@"TICKET_ORDER_RESULT_PRODUCT", nil);
    self.payNumLabel.text = MYLocalizedString(@"TICKET_ORDER_RESULT_MONEY", nil);
    self.ticketNameLabel.text = self.ticketOrderModel.subject;
    self.priceLabel.text = self.ticketOrderModel.realpay;
    
    [self createBackBtn];
}


-(void)createBackBtn{
    
    UIBarButtonItem *barItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStylePlain target:self action:@selector(back)];
    
    self.navigationItem.leftBarButtonItem = barItem;
    
    [self setNavThemeGradient];
}

- (void)back {
    
    if (self.isRePay) {
        
        [self.navigationController popToRootViewControllerAnimated:YES];
    }else {
        BOOL flag = NO;
        for (UIViewController *controller in self.navigationController.viewControllers) {
            if ([controller isKindOfClass:[CityVC class]]) {
                CityVC *cityVC =(CityVC *)controller;
                [self.navigationController popToViewController:cityVC animated:YES];
                flag = YES;
                return;
            }
        }
        
        if (!flag) {
           [self.navigationController popToRootViewControllerAnimated:YES];
        }
    }
}
- (IBAction)goCoupon:(UIButton *)sender {
    
    AccountCouponVC *ticketVC = [IGUtil loadViewController:@"AccountCouponVC" storyboard:@"Account"];
    ticketVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:ticketVC animated:YES];
}


- (IBAction)leftBtnClicked:(UIButton *)sender {
    
    if (self.payState == 1) {
        
         AllOrderListVC *allOrder = [AllOrderListVC new];
        allOrder.isLookTickerOrder = YES;
        
        [self.navigationController pushViewController:allOrder animated:YES];
    }else {
        
        [self.navigationController popViewControllerAnimated:YES];
    }
}

- (IBAction)rightBtnClicked:(UIButton *)sender {
    
    [self back];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
